package com.atao.baokede.mapper;

import com.atao.baokede.pojo.ItemOrder;
import com.atao.baokede.pojo.UserOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface ItemOrderMapper {
    /**
     * 添加订单
     * @param itemOrder
     */
    @Insert("insert into order_header(order_id,user_id,amount,address_id,status,create_time) " +
            "values(#{orderId},#{userId},#{amount},#{addressId},#{status},now())")
    void addOrder(ItemOrder itemOrder);

    /**
     * 根据订单编号查询订单
     * @param orderNo
     * @return
     */
    @Select("select * from order_header where order_id = #{orderNo}")
    ItemOrder selectByOrderNo(Long orderNo);

    /**
     * 修改订单
     * @param itemOrder
     */
    @Update("update order_header set status=#{status},pay_time=now() where order_id=#{orderId}")
    void modify(ItemOrder itemOrder);

    /**
     * 取消订单
     * @param orderId
     */
    @Update("update order_header set status=2 ,close_time = now() where order_id=#{orderId}")
    void cancelOrder(Long orderId);

    /**
     * 修改订单状态
     * @param orderNo 订单编号
     * @param status 订单状态
     */
    @Update("update order_header set status=#{status} where order_id=#{orderNo}")
    void updateStatus(Long orderNo, int status);

    /**
     * 查询用户ids
     * @param orderIds
     * @return
     */
    List<Map<String, Object>> findUserIdsByOrderIds(List<Long> orderIds);

    /**
     * 查询用户订单
     *
     * @param userId
     * @param status
     * @param orderId
     * @param itemName
     * @return
     */
    List<UserOrder> findUserOrders(Long userId, Integer status, Integer orderId, String itemName);
}
